<style>
#td_pic_list div{width:100px;float:left;margin-right: 15px;}
</style>
        <div class="pageheader notab">
            <h1 class="pagetitle">编辑产品</h1>
            <span class="pagedesc">请认真编辑产品的各项信息</span>
            
        </div><!--pageheader-->
        
        <div id="contentwrapper" class="contentwrapper lineheight21">
			
        
            <form class="stdform stdform2" method="post">
				<style>
				.form-table{ width:100%; background:#ddd;}
				.form-table th,.form-table td{ padding:15px;}
				.form-table th.title{ width:190px; background:#fcfcfc; color:#666; text-align:left;}
				.form-table th small{ font-weight:normal; color:#999; display:block;}
				.form-table td{ background:#fff; vertical-align:middle;}
				</style>
				<table class="form-table" cellspacing="1" border="0">
					<tr>
						<th class="title">商品标题<small>这里是提示您</small></th>
						<td>
							<input type="text" name="title" id="title" value="{$info.title}" class="smallinput" />
						</td>
					</tr>
					<tr>
						<th class="title">所属分类</th>
						<td>
							<select name="cate_id" default="{$info.cate_id}">
								<volist name="cates" id="vo">
									<option value="{$vo.id}">{$vo.name}</option>
								</volist>
							</select>
						</td>
					</tr>
					<tr>
						<th class="title">商品类别</th>
						<td>
							<select name="type" default="{$info.type}">
								<option value="0">虚拟商品</option>
								<option value="1">实体商品</option>
							</select>
						</td>
					</tr>
					<tr>
						<th class="title">排序权值<small>越大越靠前</small></th>
						<td>
							<input type="text" name="sort" id="sort" value="{$info.sort}" class="smallinput" />
						</td>
					</tr>
					<tr>
						<th class="title">
							封面图
							<small>点击+可以上传，点击图片可更换</small>
						</th>
						<td>
							<iframe src="{:U('upload', 'event=setPic&url='.$info['pic'])}" scrolling="no" width="100" height="100"></iframe>
							<input type="hidden" name="pic" id="pic" value="{$info.pic}" class="smallinput" />
							<script>
							function setPic(url){
								document.getElementById('pic').value = url;
							}
							</script>
						</td>
					</tr>
					<tr>
						<th class="title">
							商品图片<input value="添加图片" type="button" class="radius3" onclick="add_row()" style="border: 1px solid #f0882c;background: #fb9337;color: #fff;cursor: pointer;padding: 5px 5px;font-weight: bold;"/>
							<small>点击+可以上传，点击图片可更换</small>
						</th>
						<td id="td_pic_list">
							<php>
							for($i=0;$i<count($info['pic_list']);$i++){
							</php>
							<div>
								<iframe src="{:U('upload?event=setPath&index='.$i.'&url='.$info['pic_list'][$i])}" scrolling="no" style="width:100px; height:100px;"></iframe>
								<input type="hidden" name="pic_list[]" value="{$vo}" />
								<a href="javascript:;" onclick="del_row(this)">删除</a>
							</div>
							<php>
							}
							</php>                                               
	                        <script>
							function add_row(){
								html = '	 <div>'
									  +'		<iframe src="{:U('upload?event=setPath_n_')}" scrolling="no" style="width:100px; height:100px;"></iframe>'
									  +'		<input type="hidden" name="pic_list[]" value="" />'
									  +'		<a href="javascript:;" onclick="del_row(this)">删除</a>'
									  +'	</div>';
								size = jQuery("#td_pic_list").find("div").size();
								if(size>=14){
									alert('最多14张图片');
									return false;
								}
								jQuery("#td_pic_list").append(html.replace('_n_',"&index="+(size+1)));
							}
							
							function del_row(obj){
								jQuery(obj).parent("div").remove();
							}
							
							function setPath(index,url){
								$obbb = jQuery("#td_pic_list").find("div").eq(index-1).find("input[type=hidden]");
								jQuery("#td_pic_list").find("div").eq(index-1).find("input[type=hidden]").val(url);
							}
							</script>
						</td>
					</tr>
					<tr>
						<th class="title">市场价格</th>
						<td>
							<input type="text" name="market_price" id="market_price" value="{$info.market_price}" class="smallinput" />
						</td>
					</tr>
					<tr>
						<th class="title">销售价格</th>
						<td>
							<input type="text" name="price" id="price" value="{$info.price}" class="smallinput" />
						</td>
					</tr>
					<if condition="$_CFG['dist']['model'] eq 2">
						<tr>
							<th class="title">
							分销总比例<small>单位是%,填写数值即可</small>
							</th>
							<td>
								<input type="text" name="separate_money" id="separate_money" value="{$info.separate_dist.separate_money|default=0}" class="smallinput"/>
							</td>
						</tr>
					</if>
					<tr>
						<th class="title">各级占比<small>单位是%,填写数值即可</small></th>
						<td>
							一级佣金：<input type="text" name="separate_0" id="separate_0" value="{$info.separate_dist.separate_0|default=0}" class="smallinput" style="width:30px;"/>
							二级佣金：<input type="text" name="separate_1" id="separate_1" value="{$info.separate_dist.separate_1|default=0}" class="smallinput" style="width:30px;"/>
							三级佣金：<input type="text" name="separate_2" id="separate_2" value="{$info.separate_dist.separate_2|default=0}" class="smallinput" style="width:30px;"/>
						</td>
					</tr>
					<tr>
						<th class="title">会员折扣比例<small>单位是%,填写数值即可</small></th>
						<td>
							普通会员：<input type="text" name="dist_0" id="dist_0" value="{$info.separate_dist.dist_0|default=0}" class="smallinput" style="width:30px;"/>
							中级会员：<input type="text" name="dist_1" id="dist_1" value="{$info.separate_dist.dist_1|default=0}" class="smallinput" style="width:30px;"/>
							高级会员：<input type="text" name="dist_2" id="dist_2" value="{$info.separate_dist.dist_2|default=0}" class="smallinput" style="width:30px;"/>
						</td>
					</tr>
					<tr>
						<th class="title">赠送{$_CFG.site.points_name}<small>填写具体积分数值</small></th>
						<td>
							<input type="text" name="points" id="points" value="{$info.points|default=0}" class="smallinput" />
						</td>
					</tr>
					<tr>
						<th class="title">各级{$_CFG.site.points_name}占比<small>单位是%,填写数值即可</small></th>
						<td>
							一级{$_CFG.site.points_name}：<input type="text" name="separate_points_0" id="separate_points_0" value="{$info.separate_dist.separate_points_0|default=0}" class="smallinput" style="width:30px;"/>
							二级{$_CFG.site.points_name}：<input type="text" name="separate_points_1" id="separate_points_1" value="{$info.separate_dist.separate_points_1|default=0}" class="smallinput" style="width:30px;"/>
							三级{$_CFG.site.points_name}：<input type="text" name="separate_points_2" id="separate_points_2" value="{$info.separate_dist.separate_points_2|default=0}" class="smallinput" style="width:30px;"/>
						</td>
					</tr>
					<tr>
						<th class="title">库存</th>
						<td>
							<input type="text" name="stock" id="stock" value="{$info.stock}" class="smallinput" />
						</td>
					</tr>
					<tr>
						<th class="title">
							产品属性
							<small><a href="javascript:;" onclick="addAttr()">[添加]</a></small>
						</th>
						<td>
							<div class="">
							<input type="checkbox" name="attr_open" id="attr_open" value="1" onclick="isAttrOpen()" <if condition="$info['attr_open'] eq 1">checked</if> /> 启用
							</div>
							<style>
								.attr-table{ background:#ddd; border:0; border-spacing:1px; width:100%;}
								.attr-table tr{ background:#fff;}
								.attr-table th,.attr-table td{ vertical-align:middle;}
								.attr-value{position:relative; width:100px; height:30px; float:left;}
								.attr-value a{ background:red; color:#fff; height:32px; line-height:32px; padding:0 5px; 
										position:absolute; right:0; top:0; border-radius:0 2px 2px 0; 
									}
								input.short{ width:80px !important;}
							</style>
							<table class="attr-table" id="attr-table">
								<thead>
									<tr>
										<volist name="info['attr']" id="vo">
										<th>
											<span class="attr-value">
												<input type="text" value="{$vo}" name="attr_name[]" />
												<a href="javascript:;" onclick="delAttr(this)">X</a>
											</span>
										</th>
										</volist>
										<th>价格</th>
										<th>库存</th>
										<th>编码</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<volist name="info['attr_table']" id="vo">
									<tr>
										<volist name="vo['attr']" id="vv">
											<td><input type="text" class="short" name="attr_value[]" value="{$vv}"/></td>
										</volist>
										<td><input type="text" class="short" name="attr_price[]" value="{$vo.price}"/></td>
										<td><input type="text" class="short" name="attr_stock[]" value="{$vo.stock}"/></td>
										<td><input type="text" class="short" name="attr_code[]" value="{$vo.code}"/></td>
										<td><a href="javascript:;" onclick="delRow(this)">删除</a></td>
									</tr>
									</volist>
								</tbody>
							</table>
							<div class="" id="attr-add" style=" line-height:30px; border:1px solid #ddd; border-top:none; text-align:center;">
								<a href="javascript:;" onclick="addRow()">添加一行</a>
							</div>
							<script>
							function isAttrOpen(){
								if(jQuery("#attr_open").is(':checked')){
									jQuery("#attr-table").show();
									jQuery("#attr-add").show();
								}else{
									jQuery("#attr-table").hide();
									jQuery("#attr-add").hide();	
								}
							}
							
							// 添加属性，添加一列
							function addAttr(){
								head_html = '<th>'
										+'<span class="attr-value">'
										+'		<input type="text" value="" name="attr_name[]" />'
										+'		<a href="javascript:;" onclick="delAttr(this)">X</a>'
										+'	</span>'
										+'</th>';
								row_html = '<td><input type="text" class="short" name="attr_value[]"/></td>';
								table = jQuery("#attr-table");
								
								// 添加表头
								table.find("thead").find("tr").prepend(head_html);
								
								// 挨行添加
								table.find("tbody").find("tr").each(function(index, el){
									jQuery(el).prepend(row_html);
								});
							}
							
							function delAttr(obj){
								table = jQuery("#attr-table");
								var thisth = jQuery(obj).parent("span").parent("th");
								var thisindex = null;
								table.find("thead").find("tr").find("th").each(function(index,el){
									if(el == thisth[0]){
										thisindex = index;
										thisth.remove();
									}
								});
								table.find("tbody").find("tr").each(function(index,el){
									jQuery(el).find("td").eq(thisindex).remove();
								});
							}
							
							function addRow(){
								attr_num = jQuery(".attr-value").size();
								html = '<tr>';
								for(i=0;i<attr_num;i++){
									html += '<td><input type="text" class="short" name="attr_value[]"/></td>';
								}
								html	+= '<td><input type="text" class="short" name="attr_price[]"/></td>'
										+'<td><input type="text" class="short" name="attr_stock[]"/></td>'
										+'<td><input type="text" class="short" name="attr_code[]"/></td>'
										+'<td><a href="javascript:;" onclick="delRow(this)">删除</a></td>'
									+'</tr>';
								jQuery("#attr-table").append(html);
							}
							
							function delRow(obj){
								jQuery(obj).parent("td").parent("tr").remove();
							}
							
							jQuery(document).ready(function(e){
								isAttrOpen();
							});
							</script>
						</td>
					</tr>
					<tr>
						<th class="title">产品详情</th>
						<td>
							<textarea name="body" id="body" class="longinput" style="margin: 0px; height: 400px; max-width:640px;">{$info.body}</textarea>
						</td>
					</tr>
				</table>
				
				
				
				<p class="stdformbutton">
					<button class="submit radius2">提交</button>
					<input type="reset" class="reset radius2" value="重置" />
				</p>
			</form>
			<script src="__PUBLIC__/plugins/ueditor1.4.3/ueditor.config.js"></script>
			<script src="__PUBLIC__/plugins/ueditor1.4.3/ueditor.all.min.js"></script>
			<script>
				ue = UE.getEditor('body');
				jQuery(document).ready(function(d){
					$ = jQuery;
					//调整下拉的默认选择
					$("select").each(function(index, element) {
					  $(element).find("option[value='"+$(this).attr('default')+"']").attr('selected','selected');
					});
				});
			</script>
        
        </div><!--contentwrapper-->
        